//
//  TwoViewController.m
//  Tool
//
//  Created by 积分宝 on 16/8/18.
//  Copyright © 2016年 积分宝. All rights reserved.
//

#import "TwoViewController.h"
#import "UIcolor+TSFColor.h"
#import "UIViewController+QYCustomBackButton.h"
#import "UIView+JFBExtension.h"
#import "UIImage+TSFImage.h"
@interface TwoViewController ()<UITableViewDelegate,UITableViewDataSource>
{
  UIImageView * barImageView;
    UITableView *tabview;
}
@end

@implementation TwoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
   
    tabview = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStyleGrouped];
    tabview.y-=64;
    tabview.height+=64;
    tabview.dataSource = self;
    tabview.delegate = self;
    [self.view addSubview:tabview];

}
#pragma mark - 导航栏变透明
-(void)naviagtion{
    [self.navigationController.navigationBar setBackgroundImage:[UIImage new]
                                                  forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage = [UIImage new];
    
//    barImageView = self.navigationController.navigationBar.subviews.firstObject;
//    barImageView.backgroundColor = [UIColor redColor];
    
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    
    [self naviagtion];
    tabview.dataSource = self;
    tabview.delegate = self;

   
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
   
    [self.navigationController.navigationBar setBackgroundImage:[UIImage createImageWithColor:[UIColor greenColor]]
                                       forBarMetrics:UIBarMetricsDefault];
    
    tabview.dataSource = nil;
    tabview.delegate = nil;

     barImageView.alpha = 1.0f;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)customNavBackButtonMethod{
    [self.navigationController popToRootViewControllerAnimated:YES];
}

#pragma mark - 返回组数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
#pragma mark - 返回行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 30;
}
#pragma mark - 返回cell高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    return 100;
    
    
}
#pragma mark - 设置tableViewCell
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static  NSString *ss=@"hello word";
    
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:ss];
    
    if(!cell){
        
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ss];
        //显示右边箭头
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    UITextField *field = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, 300, 60)];\
    [cell addSubview:field];
    
    return cell;
    
}
#pragma mark - 监听tableViewCell点击
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //点击cell背景恢复正常状态
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
                                                                  
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    CGFloat minAlphaOffset = - 64;
    CGFloat maxAlphaOffset = 200;
    CGFloat offset = scrollView.contentOffset.y;
    CGFloat alpha = (offset - minAlphaOffset) / (maxAlphaOffset - minAlphaOffset);
    barImageView.alpha = alpha;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.01f;
}

@end
